﻿// Json测试
// var data = [{ "id": 1, "circle": "2", "pressure": "3", "temperature": "4", "flow": "123" },
// // { "id": 2, "circle": "2", "pressure": "5", "temperature": "1", "flow": "321" }];
// //var datajsonold = JSON.stringify(data);
// //var datalist = [];
// //datalist.push({ "id": 1, "circle": "1", "pressure": "3", "temperature": "4", "flow": "123", "time": "2018/03/29 15:46:30" });
// //datalist.push({ "id": 2, "circle": "1" });
// //datalist.push({ "id": 3, "circle": "1" });
// //datalistjson = JSON.stringify(datalist)

$(function () {
    var p = $('#menu').tabs().tabs('tabs')[3];
    var mb = p.panel('options').tab.find('a.tabs-inner');
    mb.menubutton({
        menu: '#graphDDL',
        iconCls: 'icon-large-chart'
    }).click(function () {
        $('#menu').tabs('select', 1);
    });;

    var timer;
    //开启生成
    $("#startSim").click(function () {
        BindingList();
        timer = setInterval(function () { BindingList() }, 1000);
        $.ajax({
            type: "post",
            url: "/ShieldSimView/StartSim",
            dataType: "text",
            success: function (result) {
                console.log(result);
            },
            error: function (result) {
                console.log(result);
            }
        })

    })
    //停止生成
    $("#stopSim").click(function () {
        clearInterval(timer);
        $.ajax({
            type: "post",
            url: "/ShieldSimView/StopSim",
            dataType: "text",
            success: function (result) {
                console.log(result);
            },
            error: function (result) {
                console.log(result);
            }
        })

    })
    //绑定最新列表30条数据
    function BindingList() {
        $.ajax({
            type: "post",
            url: "/ShieldSimView/GetList30Data",
            dataType: "Json",
            success: function (result) {
                ObjectToListView(result);
            },
            error: function (result) {
                console.log(result);
            }
        })
    }

    //转换对象到数据中 往页面ListView上赋值
    function ObjectToListView(obj) {
        $("table[name=listView]").html(addhtmlviewdom(obj));
        //增加行
        $.each(obj, function (i, item) {
            $("#listView" + (i + 1) + "order").html((i + 1));
            $("input[name=listView" + (i + 1) + "id]").val(item.Id);
            $("input[name=listView" + (i + 1) + "circle]").val(item.Circle);
            $("input[name=listView" + (i + 1) + "groudpressure]").val(item.GroundPressure);
            $("input[name=listView" + (i + 1) + "temperature]").val(item.Temperature);
            $("input[name=listView" + (i + 1) + "flow]").val(item.Flow);
            $("input[name=listView" + (i + 1) + "generatetime]").val(item.GenerateTime);
            $("input[name=list" + (i + 1) + "id]").val(item.Id);
        });
    }
    function addhtmlviewdom(obj) {
        var htmldom;
        for (i = 1; i <= obj.length; i++) {
            var htmldomtemp = "<tr>" +
            "<td style=\"width:20px\" id=\"listView" + i + "order\"></td>" +
            "<td style=\"width:80px\"><input name=\"listView" + i + "id\"/></td>" +
            "<td style=\"width:100px\"><input name=\"listView" + i + "circle\"/></td>" +
            "<td style=\"width:100px\"><input name=\"listView" + i + "groudpressure\"/></td>" +
            "<td style=\"width:50px\"><input name=\"listView" + i + "temperature\"/></td>" +
            "<td style=\"width:100px\"><input name=\"listView" + i + "flow\"/></td>" +
            "<td style=\"width:150px\"><input name=\"listView" + i + "generatetime\"/></td>" +
            "</tr>";
            htmldom += htmldomtemp;//这里更改也可以倒序
        }
        return htmldom;
    }

    var whichgraph;
    //折线图数据绑定
    $("#showZheXianTu").click(function () {
        $("#zhexiantu").show();
        $("#zhuzhuangtu").hide();
        whichgraph = "PolyLine";
        $.ajax({
            type: "post",
            url: "/ShieldSimView/SearchLine",
            dataType: "Json",
            data: {
                "starttime": "2000-1-1 12:01:01",
                "endtime": "2500-1-1 12:01:01"
            },
            success: function (result) {
                ObjectToPolyLine(result);
            },
            error: function (result) {
                console.log(result);
            }
        })
    });
    //柱状图数据绑定
    $("#showZhuZhuangTu").click(function () {
        $("#zhexiantu").hide();
        $("#zhuzhuangtu").show();
        whichgraph = "BarGraph";
        $.ajax({
            type: "post",
            url: "/ShieldSimView/SearchHistory",
            dataType: "Json",
            data: {
                "starttime": "2000-1-1 12:01:01",
                "endtime": "2500-1-1 12:01:01"
            },
            success: function (result) {

                ObjectToBarGraph(result);
            },
            error: function (result) {
                console.log(result);
            }
        })
    });

    //往页面图像上赋值--折线
    function ObjectToPolyLine(obj) {
        var myChart = echarts.init(document.getElementById('zhexiantu'));//不能用jq似乎，找的是dom对象
        option = {
            title: {
                text: '盾构系统动态数据图像'
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    crossStyle: {
                        color: '#999'
                    }
                }
            },
            toolbox: {
                feature: {
                    dataView: { show: true, readOnly: false },
                    magicType: { show: true, type: ['line', 'bar'] },
                    restore: { show: true },
                    saveAsImage: { show: true }
                }
            },
            legend: {
                data: ['土压', '流量', '温度']
            },
            dataZoom: [//给x轴设置滚动条
            {
                start: 0,//默认为0
                end: 100 - 1500 / 31,//默认为100
                type: 'slider',
                show: true,
                xAxisIndex: [0],
                handleSize: 0,//滑动条的 左右2个滑动条的大小
                height: 8,//组件高度
                left: 50, //左边的距离
                right: 40,//右边的距离
                bottom: 26,//右边的距离
                handleColor: '#ddd',//h滑动图标的颜色
                handleStyle: {
                    borderColor: "#cacaca",
                    borderWidth: "1",
                    shadowBlur: 2,
                    background: "#ddd",
                    shadowColor: "#ddd",
                },
                fillerColor: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
                    //给颜色设置渐变色 前面4个参数，给第一个设置1，第四个设置0 ，就是水平渐变
                    //给第一个设置0，第四个设置1，就是垂直渐变
                    offset: 0,
                    color: '#1eb5e5'
                }, {
                    offset: 1,
                    color: '#5ccbb1'
                }]),
                backgroundColor: '#ddd',//两边未选中的滑动条区域的颜色
                showDataShadow: false,//是否显示数据阴影 默认auto
                showDetail: false,//即拖拽时候是否显示详细数值信息 默认true
                handleIcon: 'M-292,322.2c-3.2,0-6.4-0.6-9.3-1.9c-2.9-1.2-5.4-2.9-7.6-5.1s-3.9-4.8-5.1-7.6c-1.3-3-1.9-6.1-1.9-9.3c0-3.2,0.6-6.4,1.9-9.3c1.2-2.9,2.9-5.4,5.1-7.6s4.8-3.9,7.6-5.1c3-1.3,6.1-1.9,9.3-1.9c3.2,0,6.4,0.6,9.3,1.9c2.9,1.2,5.4,2.9,7.6,5.1s3.9,4.8,5.1,7.6c1.3,3,1.9,6.1,1.9,9.3c0,3.2-0.6,6.4-1.9,9.3c-1.2,2.9-2.9,5.4-5.1,7.6s-4.8,3.9-7.6,5.1C-285.6,321.5-288.8,322.2-292,322.2z',
                filterMode: 'filter',
            },
            //下面这个属性是里面拖动
            {
                type: 'inside',
                show: true,
                xAxisIndex: [0],
                start: 0,//默认为1
                end: 100 - 1500 / 31,//默认为100
            },
            ],
            xAxis: [
            {
                type: 'category',
                boundaryGap: false,
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].GenerateTime);
                        i++;
                    }
                    return list;
                }()
            }
            ],
            yAxis: [
            {
                type: 'value',
                name: '土压',
                axisLabel: {
                    formatter: '{value} Pa'
                }
            },
            {
                type: 'value',
                name: '流量',
                axisLabel: {
                    formatter: '{value} ml'
                }
            },
            {
                type: 'value',
                name: '温度',
                offset: 60,
                axisLabel: {
                    formatter: '{value} ℃'
                }
            }

            ],
            series: [
            {
                name: '土压',
                type: 'line',
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].GroundPressure);
                        i++;
                    }
                    return list;
                }()
            },
            {
                name: '流量',
                type: 'line',
                yAxisIndex: 1,
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].Flow);
                        i++;
                    }
                    return list;
                }()
            },
            {
                name: '温度',
                type: 'line',
                yAxisIndex: 2,
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].Temperature);
                        i++;
                    }
                    return list;
                }()
            }
            ]
        };
        myChart.setOption(option);
    }

    //往页面图像上赋值--柱状
    function ObjectToBarGraph(obj) {
        var myChart = echarts.init(document.getElementById('zhuzhuangtu'));//不能用jq似乎，找的是dom对象
        option = {
            title: {
                text: '盾构系统动态数据图像'
            },
            tooltip: {
                trigger: 'item',
                axisPointer: {
                    type: 'cross',
                    crossStyle: {
                        color: '#999'
                    }
                }
            },
            toolbox: {
                show: true,
                feature: {
                    mark: { show: true },
                    dataView: { show: true, readOnly: false },
                    magicType: { show: true, type: ['line', 'bar'] },
                    restore: { show: true },
                    saveAsImage: { show: true }
                }
            },
            legend: {
                top: -5,
                data: ['土压最大值', '流量最大值', '温度最大值', "",
                '土压最小值', '流量最小值', '温度最小值', "",
                '土压平均值', '流量平均值', '温度平均值'
                ]
            },
            grid: {
                backgroundColor: 'rgba(221,160,221,0.5)',
            },
            dataZoom: [//给x轴设置滚动条
            {
                start: 0,//默认为0
                end: 100 - 1500 / 31,//默认为100
                type: 'slider',
                show: true,
                xAxisIndex: [0, 1],
                handleSize: 0,//滑动条的 左右2个滑动条的大小
                height: 8,//组件高度
                left: 50, //左边的距离
                right: 40,//右边的距离
                bottom: 26,//右边的距离
                handleColor: '#ddd',//h滑动图标的颜色
                handleStyle: {
                    borderColor: "#cacaca",
                    borderWidth: "1",
                    shadowBlur: 2,
                    background: "#ddd",
                    shadowColor: "#ddd",
                },
                fillerColor: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
                    //给颜色设置渐变色 前面4个参数，给第一个设置1，第四个设置0 ，就是水平渐变
                    //给第一个设置0，第四个设置1，就是垂直渐变
                    offset: 0,
                    color: '#1eb5e5'
                }, {
                    offset: 1,
                    color: '#5ccbb1'
                }]),
                backgroundColor: '#ddd',//两边未选中的滑动条区域的颜色
                showDataShadow: false,//是否显示数据阴影 默认auto
                showDetail: false,//即拖拽时候是否显示详细数值信息 默认true
                handleIcon: 'M-292,322.2c-3.2,0-6.4-0.6-9.3-1.9c-2.9-1.2-5.4-2.9-7.6-5.1s-3.9-4.8-5.1-7.6c-1.3-3-1.9-6.1-1.9-9.3c0-3.2,0.6-6.4,1.9-9.3c1.2-2.9,2.9-5.4,5.1-7.6s4.8-3.9,7.6-5.1c3-1.3,6.1-1.9,9.3-1.9c3.2,0,6.4,0.6,9.3,1.9c2.9,1.2,5.4,2.9,7.6,5.1s3.9,4.8,5.1,7.6c1.3,3,1.9,6.1,1.9,9.3c0,3.2-0.6,6.4-1.9,9.3c-1.2,2.9-2.9,5.4-5.1,7.6s-4.8,3.9-7.6,5.1C-285.6,321.5-288.8,322.2-292,322.2z',
                filterMode: 'filter',
            },
            //下面这个属性是里面拖动
            {
                type: 'inside',
                show: true,
                xAxisIndex: [0, 1],
                start: 0,//默认为1
                end: 100 - 1500 / 31,//默认为100
            },
            ],
            xAxis: [
            {
                type: 'category',
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].TimePoint);
                        i++;
                    }
                    return list;
                }(),
                boundaryGap: true
            },
            {
                type: 'category',
                axisLine: { show: false },
                axisTick: { show: false },
                axisLabel: { show: false },
                splitArea: { show: false },
                splitLine: { show: false },
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].TimePoint);
                        i++;
                    }
                    return list;
                }(),
                boundaryGap: true
            },
            ],
            yAxis: [
            {
                type: 'value',
                name: '土压',
                axisLabel: {
                    formatter: '{value} Pa'
                }
            },
            {
                type: 'value',
                name: '流量',
                axisLabel: {
                    formatter: '{value} ml'
                }
            },
            {
                type: 'value',
                name: '温度',
                offset: 60,
                axisLabel: {
                    formatter: '{value} ℃'
                }
            }

            ],
            series: [
            {
                name: '土压最小值',
                type: 'bar',
                itemStyle: { normal: { color: 'rgba(193,35,43,1)', label: { show: true } } },
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].MinGroundPressure);
                        i++;
                    }
                    return list;
                }()
            },
            {
                name: '流量最小值',
                type: 'bar',
                yAxisIndex: 1,
                itemStyle: { normal: { color: 'rgba(181,195,52,1)', label: { show: true, textStyle: { color: '#27727B' } } } },
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].MinFlow);
                        i++;
                    }
                    return list;
                }()
            },
            {
                name: '温度最小值',
                type: 'bar',
                yAxisIndex: 2,
                itemStyle: { normal: { color: 'rgba(252,206,16,1)', label: { show: true, textStyle: { color: '#912CEE' } } } },
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].MinTemperature);
                        i++;
                    }
                    return list;
                }()
            },
            {
                name: '土压最大值',
                type: 'bar',
                xAxisIndex: 1,
                itemStyle: { normal: { color: 'rgba(193,35,43,0.5)', label: { show: true, formatter: function (p) { return p.value > 0 ? (p.value + '\n') : ''; } } } },
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].MaxGroundPressure);
                        i++;
                    }
                    return list;
                }()
            },
            {
                name: '流量最大值',
                type: 'bar',
                xAxisIndex: 1,
                yAxisIndex: 1,
                itemStyle: { normal: { color: 'rgba(181,195,52,0.5)', label: { show: true, textStyle: { color: '#458B00' } } } },
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].MaxFlow);
                        i++;
                    }
                    return list;
                }()
            },
            {
                name: '温度最大值',
                type: 'bar',
                xAxisIndex: 1,
                yAxisIndex: 2,
                itemStyle: { normal: { color: 'rgba(252,206,16,0.5)', label: { show: true, textStyle: { color: '#8B7500' } } } },
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].MaxTemperature);
                        i++;
                    }
                    return list;
                }()
            },
            {
                name: '土压平均值',
                type: 'bar',
                xAxisIndex: 1,
                itemStyle: { normal: { color: 'rgba(193,35,43,0.5)' } },
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].AvgGroundPressure);
                        i++;
                    }
                    return list;
                }()
            },
            {
                name: '流量平均值',
                type: 'bar',
                xAxisIndex: 1,
                yAxisIndex: 1,
                itemStyle: { normal: { color: 'rgba(181,195,52,0.5)' } },
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].AvgFlow);
                        i++;
                    }
                    return list;
                }()
            },
            {
                name: '温度平均值',
                type: 'bar',
                xAxisIndex: 1,
                yAxisIndex: 2,
                itemStyle: { normal: { color: 'rgba(252,206,16,0.5)' } },
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].AvgTemperature);
                        i++;
                    }
                    return list;
                }()
            },
            {
                name: '土压平均值',
                type: 'bar',
                itemStyle: { normal: { color: 'rgba(193,35,43,0.5)' } },
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].AvgGroundPressure);
                        i++;
                    }
                    return list;
                }()
            },
            {
                name: '流量平均值',
                type: 'bar',
                yAxisIndex: 1,
                itemStyle: { normal: { color: 'rgba(181,195,52,0.5)' } },
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].AvgFlow);
                        i++;
                    }
                    return list;
                }()
            },
            {
                name: '温度平均值',
                type: 'bar',
                yAxisIndex: 2,
                itemStyle: { normal: { color: 'rgba(252,206,16,0.5)' } },
                data: function () {
                    var list = [];
                    var i = 0;
                    while (i < obj.length) {
                        list.push(obj[i].AvgTemperature);
                        i++;
                    }
                    return list;
                }()
            },
            ]
        };
        myChart.setOption(option);
    }

    //图像分页中搜索功能实现
    $("#searchGraph").click(function () {

        var starttime = $(this).parent().find("#starttime").val();
        var endtime = $(this).parent().find("#endtime").val();
        if (whichgraph == "PolyLine") {
            $.ajax({
                type: "post",
                url: "/ShieldSimView/SearchLine",
                dataType: "Json",
                data: {
                    "starttime": starttime,
                    "endtime": endtime
                },
                success: function (result) {
                    ObjectToPolyLine(result);
                },
                error: function (result) {
                    console.log(result);
                }
            })
        } else {
            $.ajax({
                type: "post",
                url: "/ShieldSimView/SearchHistory",
                dataType: "Json",
                data: {
                    "starttime": starttime,
                    "endtime": endtime
                },
                success: function (result) {
                    ObjectToBarGraph(result);
                },
                error: function (result) {
                    console.log(result);
                }
            })
        }
    });
});

//window固有的方法写在jq的匿名函数外，区分一下
//搜索起止日期间数据，并绑定
function searchListData(obj) {

    var starttime = $(obj).parent().find("#starttime").val();
    var endtime = $(obj).parent().find("#endtime").val();
    getsearchsubmit(starttime, endtime);
}

//搜索用ajax
//提供起始和终止时间，返回json到页面绑定
function getsearchsubmit(start, end) {
    //var data = "starttime="+start+"&endtime="+end+"";
    //datate.push(" 'start':" + start + " ");
    $.ajax({
        url: "/ShieldSimView/SearchList",
        async: false,
        data: {
            "starttime": start,
            "endtime": end
        },
        type: "post",
        //contentType: 'application/json',
        //dataType: "json",//返回应该是json对象
        success: function (result) {
            ObjectToListEdit(result);
        },
        error: function (result) {
            console.log("错误，无法正确刷新数据" + result + "");
        }
    });
}

//转换对象到数据中 往页面ListEdit上赋值
function ObjectToListEdit(obj) {
    $("table[name=listEdit]").html(addhtmleditdom(obj));
    //增加行
    $.each(obj, function (i, item) {
        $("input[name=listEdit" + (i + 1) + "id]").val(item.Id);
        $("input[name=listEdit" + (i + 1) + "circle]").val(item.Circle);
        $("input[name=listEdit" + (i + 1) + "groudpressure]").val(item.GroundPressure);
        $("input[name=listEdit" + (i + 1) + "temperature]").val(item.Temperature);
        $("input[name=listEdit" + (i + 1) + "flow]").val(item.Flow);
        $("input[name=listEdit" + (i + 1) + "generatetime]").val(item.GenerateTime);
        $("input[name=listEdit" + (i + 1) + "trueid]").val(item.Id);
    });
}
function addhtmleditdom(obj) {
    var htmldom;
    for (i = 1; i <= obj.length; i++) {
        var htmldomtemp = "<tr>" +
        "<td style=\"width:20px\"><input type=\"checkbox\" class=\"usercustomcheck\"/></td>" +
        "<td style=\"width:50px\"><input name=\"listEdit" + i + "id\"/></td>" +
        "<td style=\"width:100px\"><input name=\"listEdit" + i + "circle\"/></td>" +
        "<td style=\"width:100px\"><input name=\"listEdit" + i + "groudpressure\"/></td>" +
        "<td style=\"width:50px\"><input name=\"listEdit" + i + "temperature\"/></td>" +
        "<td style=\"width:100px\"><input name=\"listEdit" + i + "flow\"/></td>" +
        "<td style=\"width:150px\"><input name=\"listEdit" + i + "generatetime\"/></td>" +
        "<td><input value=\"修改\" type=\"button\" onclick=\"EditCurrentData(this)\" /></td>" +
        "<td><input value=\"删除\" type=\"button\" onclick=\"DeleteCurrentData(this)\" /></td>" +
        "<td><input name=\"listEdit" + i + "trueid\" type=\"hidden\"/></td></tr>";
        htmldom += htmldomtemp;
    }
    if (obj.length == 0) {
        htmldom += "<tr><td colspan=\"8\" style=\"font-size:20px;font-family:'Microsoft YaHei'\">这儿并没有数据可以展示</td></tr>";
    }
    return htmldom;
}

//删除当前数据(确定界面 反馈界面)
function DeleteCurrentData(obj) {

    var val = $(obj).parents("tr").find("input").last().val();
    $.messager.confirm("操作提示", "您确定要执行删除操作吗？", function (data) {
        if (data) {
            $.ajax({
                url: "/ShieldSimView/DeleteDataById",
                data: {
                    "id": val
                },
                type: "post",
                success: function (result) {
                    if (result) {
                        $.messager.alert("操作提示", "删除成功！", "info");
                        //此处可以假写一个搜索按钮的点击事件，让表重新刷一遍，这里不写是为了测试result返回false的状态
                    } else {
                        $.messager.alert("操作提示", "已经删除该数据，请勿重复操作！", "warning");
                        searchListData($("#searchlist"));
                    }
                },
                error: function (result) {
                    $.messager.show({
                        title: "操作提示",
                        msg: "服务器异常！",
                        showType: 'slide',
                        timeout: 5000
                    });
                }
            })
        }
        else {
            $.messager.show({
                title: "操作提示",
                msg: "已经取消删除",
                showType: 'slide',
                timeout: 5000
            });
        }
    });
}

//修改当前数据
function EditCurrentData(obj) {
    var $objparent = $(obj).parents("tr").find("input");
    var val = $objparent.last().val();
    var data = {
        "Id": val,
        "Circle": $objparent.eq(2).val(),
        "GroundPressure": $objparent.eq(3).val(),
        "Temperature": $objparent.eq(4).val(),
        "Flow": $objparent.eq(5).val(),
        "GenerateTime": $objparent.eq(6).val()
    },
    editdata = JSON.stringify(data);

    $.confirm({
        title: '确定更新为修改后的数据么?',
        columnClass: 'col-md-4 col-md-offset-8',
        backgroundDismiss: true,
        animation: 'zoom',
        closeAnimation: 'scale',
        autoClose: 'cancel|6000',
        content: '注意：正在进行一个更改数据的操作(无操作6s后关闭)',
        buttons: {
            confirm: {
                text: '确认',
                action: function () {
                    $.ajax({
                        url: "/ShieldSimView/UpdateDataByModel",
                        data: editdata,
                        type: "post",
                        contentType: 'application/json',
                        success: function (result) {
                            if (result) {
                                $.alert('更新成功！');
                            } else {
                                $.alert('数据已被更新，请勿重复更新！');
                            }
                        },
                        error: function (result) {
                            console.log("服务器异常！");
                        }
                    })
                }
            },
            cancel: {
                text: '取消',
                action: function () {
                    $.alert('取消编辑');
                }
            }
        }
    });
}

//删除批量数据(确定界面 反馈界面)
function DeleteLotsOfData(obj) {

    var array = [];
    var opcheck = $(obj).parents("div").eq(0).find(".usercustomcheck");//获取所有checkbox
    if (opcheck.length == 0) { $.messager.alert("操作提示", "尚未查到数据，请查询后再操作！", "info"); return false; };//没找到直接不提交
    $.each(opcheck, function (i, item) {
        if ($(item).is(':checked')) {
            array.push($(item).parents("tr").find("input").last().val())
        }
    })
    $.messager.confirm("操作提示", "您确定要执行删除操作吗？", function (data) {
        if (data) {
            $.ajax({
                url: "/ShieldSimView/DeleteDataByIdArray",
                data: {
                    "arrayId": array
                },
                type: "post",
                success: function (result) {
                    if (result) {
                        $.messager.alert("操作提示", "删除成功！", "info");
                    } else {
                        $.messager.alert("操作提示", "已经删除所选数据，请勿重复操作！", "warning");
                        searchListData($("#searchlist"));
                        //此处可以假写一个搜索按钮的点击事件，让表重新刷一遍，懒得弄了。。
                    }
                },
                error: function (result) {
                    $.messager.show({
                        title: "操作提示",
                        msg: "服务器异常！",
                        showType: 'slide',
                        timeout: 5000
                    });
                }
            })
        }
        else {
            $.messager.show({
                title: "操作提示",
                msg: "已经取消删除",
                showType: 'slide',
                timeout: 5000
            });
        }
    });
}

//修改批量数据
function EditLotsOfData(obj) {
    editdata = [];
    var opcheck = $(obj).parents("div").eq(0).find(".usercustomcheck");//获取所有checkbox
    if (opcheck.length == 0) { $.messager.alert("操作提示", "尚未查到数据，请查询后再操作！", "info"); return false; };//没找到直接不提交
    $.each(opcheck, function (i, item) {
        if ($(item).is(':checked')) {
            var $objparent = $(item).parents("tr").find("input");//找checkbox上唯一的tr父级
            var val = $objparent.last().val();
            var data = {
                "Id": val,
                "Circle": $objparent.eq(2).val(),
                "GroundPressure": $objparent.eq(3).val(),
                "Temperature": $objparent.eq(4).val(),
                "Flow": $objparent.eq(5).val(),
                "GenerateTime": $objparent.eq(6).val()
            };
            editdata.push(data);
        }
    })
    var modellist = JSON.stringify(editdata);

    $.confirm({
        title: '确定更新为修改后的数据么?',
        columnClass: 'col-md-4 col-md-offset-8',
        backgroundDismiss: true,
        animation: 'zoom',
        closeAnimation: 'scale',
        autoClose: 'cancel|6000',
        content: '注意：正在进行一个更改数据的操作(无操作6s后关闭)',
        buttons: {
            confirm: {
                text: '确认',
                action: function () {
                    $.ajax({
                        url: "/ShieldSimView/UpdataDataByModelList",
                        data: modellist,
                        type: "post",
                        contentType: 'application/json',
                        success: function (result) {
                            if (result) {
                                $.alert('更新成功！');
                            } else {
                                $.alert('数据已被更新，请勿重复更新！');
                            }
                        },
                        error: function (result) {
                            console.log("服务器异常！");
                        }
                    })
                }
            },
            cancel: {
                text: '取消',
                action: function () {
                    $.alert('取消编辑');
                }
            }
        }
    });
}
//保留俩位小数
function ChangeNumberFormart(val) {
    if (val != null) {
        return Math.round(val * 100) / 100;
    } else {
        return 0;
    }
}
//转换时间为常规时间 yyyy-MM-dd HH:mm:ss
function ChangeDateFormat(val) {
    if (val != null) {
        var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10));
        //月份为0-11，所以+1，月份小于10时补个0
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;//+1是因为默认date中月份是0开始 故9前要加0,后面类似同理
        var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var currentHour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var currentMinetes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var currentSecond = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
        return date.getFullYear() + "-" + month + "-" + currentDate + " " + currentHour + ":" + currentMinetes + ":" + currentSecond;
    } else {
        return "";
    }
}
//转换时间为JS date时间
function ChangeDateFormatToJsDate(val) {
    if (val != null) {
        return new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10));
    } else {
        console.log("时间转换失败！请检查数据！");
    }
}